package com.responsibilityChain.exampleInMVC;

public class Test {
    public static void main(String[] args) {

        //查看dispaterServlet类中的方法 请求首先进入的就是DispatcherServlet
        //在org.springframework.web.servlet 包下

        /**
         * todo 在doDispatch 方法中有一个变量叫做 HandlerExecutionChain
         *
         * protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception {
         *         HttpServletRequest processedRequest = request;
         *         HandlerExecutionChain mappedHandler = null;
         *         boolean multipartRequestParsed = false;
         *         WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
         *
         *          try {
         *                     processedRequest = this.checkMultipart(request);
         *                     multipartRequestParsed = processedRequest != request;
         *                     mappedHandler = this.getHandler(processedRequest);
         *                     if (mappedHandler == null) {
         *                         this.noHandlerFound(processedRequest, response);
         *                         return;
         *                     }
         *          .....
         *
         *
          todo 在try里面 mappedHandler = this.getHandler(processedRequest); 这里面拿到了HandlerExecutionChain对象
         *
         *
         * todo 然后调用了 mappedHandler 的applyPreHandle方法
         *  if (!mappedHandler.applyPreHandle(processedRequest, response)) {return;}
         *
         * todo 接着去看这个 applyPreHandle方法 做了哪些工作
         * boolean applyPreHandle(HttpServletRequest request, HttpServletResponse response) throws Exception {
         *         HandlerInterceptor[] interceptors = this.getInterceptors();
         *         if (!ObjectUtils.isEmpty(interceptors)) {
         *             for(int i = 0; i < interceptors.length; this.interceptorIndex = i++) {
         *                 HandlerInterceptor interceptor = interceptors[i];
         *                 if (!interceptor.preHandle(request, response, this.handler)) {
         *                     this.triggerAfterCompletion(request, response, (Exception)null);
         *                     return false;
         *                 }
         *             }
         *         }
         *
         *         return true;
         *     }
         * todo 可以看到applyPreHandle方法 里面拿到了拦截器的数组 ，如果拦截器不是空，遍历所有拦截器
         * todo 执行拦截器的preHandle方法，如果方法返回的是false，
         * todo 继续调用triggerAfterCompletion 方法 他的内部也是遍历所有拦截器，调用拦截器的 afterCompletion方法
         *
         */


    }
}
